<?php

class MenuController extends Controller
{



    /*
     * 获取菜单列表
     *
     */
    public function actionGetMenuList()
    {
        try
        {


            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //初始化
            $searchsql = Util::initSearchSql();


            //获取count
            $totalcount = AdminMenu::model()->count($searchsql);


            Util::responseList($totalcount,AdminMenuService::getMenuList($searchsql));


        }catch (Exception $e)
        {

            Util::responseErrorMsg($e->getMessage());

        }
    }

    /*
     * 新增菜单
     *
     */
    public function actionAddMenu()
    {

        try
        {


            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $menu_name = Util::getParamNotEmpty("menu_name");
            $parent_id = Util::getParamNotEmpty("parent_id");
            $url = Util::getParamNotEmpty("url");

            //添加菜单
            AdminMenuService::addMenu($menu_name,$parent_id,$url);




             Util::responseObj(MsgConst::RETURN_SUCCESS);



        }catch (Exception $e)
        {

            Util::responseErrorMsg($e->getMessage());

        }


    }

    /*
     * 删除菜单
     *
     */

    public function actionDeleteMenu()
    {

        try
        {


            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $menu_id = Util::getParamNotEmpty("menu_id");

            //添加菜单
            AdminMenuService::deleteMenu($menu_id);




            Util::responseObj(MsgConst::RETURN_SUCCESS);



        }catch (Exception $e)
        {

            Util::responseErrorMsg($e->getMessage());

        }


    }


    /*
    * 修改菜单
    *
    */

    public function actionUpdateMenu()
    {

        try
        {


            //检测
            $user_id = SessionService::getUserIDBySessionid();

            //参数验证
            $menu_id = Util::getParamNotEmpty("menu_id");

            //参数验证
            $menu_name = Util::getParamNotEmpty("menu_name");
            $url = Util::getParamNotEmpty("url");


            //添加菜单
            AdminMenuService::updateMenu($menu_id,$menu_name,$url);




            Util::responseObj(MsgConst::RETURN_SUCCESS);



        }catch (Exception $e)
        {

            Util::responseErrorMsg($e->getMessage());

        }


    }
}